import { get, post } from '@/request/http'
import qs from 'qs'
import { clientId } from '@/config/index'
// 检查手机号
export function checkUserPhone (data) {
  const url = process.env.VUE_APP_CDHNTECH_API + '/hnUser/checkUserPhone'
  return get(url, data)
}
// 检查用户账号
export function checkUserUserName (data) {
  const url = process.env.VUE_APP_CDHNTECH_API + '/hnUser/checkUserUserName'
  return get(url, data)
}
// 使用code到统一授权中心注册用户信息
export function getUserBaseInfoJson ({ code, appKey }) {
  const url = '/dingtalk/base/getUserBaseInfoJson'
  return get(url, { code, appKey })
}
// 子系统AccessToken获取
export function getAccessToken ({ appSecret, appKey }) {
  const url = '/dingtalk/base/getAccessToken'
  return get(url, { appSecret, appKey })
}
// 使用AccessToken和code进行登录
export function getLoginUser ({ accessToken, code }) {
  const url = '/dingtalk/base/getLoginUser'
  return get(url, { accessToken, code })
}
// 登录
export function loginIn (data) {
  const url = process.env.VUE_APP_OATH_API + '/oauth/token'
  const headers = {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
  return post(url, qs.stringify(data), headers)
}

// 刷新token
export function refresh (data) {
  const url = process.env.VUE_APP_OATH_API + '/oauth/token'
  const headers = {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
  return post(url, qs.stringify(data), headers)
}

// 获取用户信息
export function getUserinfo () {
  const url = process.env.VUE_APP_OATH_API + '/users/info'
  return get(url)
}
// 获取菜单 new
export function getNewMenuList () {
  const url = process.env.VUE_APP_CDHNTECH_API + '/hnResource/getUserTree'
  return get(url)
}
// 获取菜单
export function getMenuList () {
  const url = process.env.VUE_APP_AUTHORITY_API + '/res/useridtree'
  const params = {
    resType: 1,
    clientId: clientId
  }
  return get(url, params)
}

// 退出
export function logout () {
  const url = process.env.VUE_APP_OATH_API + '/logout'
  const params = {
    lient_id: clientId,
    redirect_uri: window.location.href,
    logout_type: 'slo'
  }
  return get(url, params)
}

// 修改密码
export function forceModify (data) {
  const url = process.env.VUE_APP_USER_API + '/users/pscode/forceModify'
  return post(url, data)
}

// 用户管理授权获取所有角色
export function getAllRole (params) {
  const url = process.env.VUE_APP_CDHNTECH_API + '/logout'
  return get(url, params)
}

// 用户管理授权获取已有角色
export function getCurrentRole (params) {
  const url = process.env.VUE_APP_CDHNTECH_API + '/hnRole/queryHnRoleByIdList'
  return post(url, params)
}

// 用户管理授权
export function authorize (params) {
  const url = process.env.VUE_APP_CDHNTECH_API + '/hnUser/saveUserAndRole'
  return post(url, params)
}

// 用户管理列表
export function getPageUser (params) {
  const url = process.env.VUE_APP_CDHNTECH_API + '/hnUser/getPageHnUser'
  return post(url, params)
}

// 用户管理-删除用户
export function delUser (params) {
  const url = process.env.VUE_APP_CDHNTECH_API + '/hnUser/deleteByPrimaryKey'
  return post(url, params)
}

// 用户管理-批量删除用户
export function deleteUserBatch (params) {
  const url = process.env.VUE_APP_CDHNTECH_API + '/hnUser/deleteUserBatch'
  return post(url, params)
}

// 根据获取用户信息
export function getUserById (params) {
  const url = process.env.VUE_APP_CDHNTECH_API + '/hnUser/getHnUserById'
  return get(url, params)
}

// 新增用户信息
export function addUser (params) {
  const url = process.env.VUE_APP_CDHNTECH_API + '/hnUser/insertSelective'
  return post(url, params)
}

// 编辑用户信息
export function updateUser (params) {
  const url = process.env.VUE_APP_CDHNTECH_API + '/hnUser/updateByPrimaryKeySelective'
  return post(url, params)
}

// 新增用户信息
export function pwaReset (params) {
  const url = process.env.VUE_APP_CDHNTECH_API + '/ycloud-user/users/pscode/forceReset'
  return post(url, params)
}
